package com.yingxin.yxerp.module.organization.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.yingxin.yxerp.module.organization.vo.resp.DepartmentRespVo;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class SeniorityHelper {

    public static String calc(Date ru, Date chu) {
        if (chu == null) {
            chu = new Date();
        }
        if (ru == null) {
            ru = new Date();
        }
        Calendar from = Calendar.getInstance();
        from.setTime(ru);
        Calendar to = Calendar.getInstance();
        to.setTime(chu);
        int year = to.get(Calendar.YEAR) - from.get(Calendar.YEAR);
        return year > 0 ? "" + year : "不满一年";
    }

    public static String getDeptNames(List<DepartmentRespVo> departmentRespVoList) {
        StringBuffer buffer = new StringBuffer();
        if (CollectionUtil.isNotEmpty(departmentRespVoList)) {
            departmentRespVoList.forEach(departmentRespVo -> {
                buffer.append(departmentRespVo.getName()).append("/");
            });
            buffer.deleteCharAt(buffer.length() - 1);
        }
        return buffer.toString();
    }
}
